<?php
/**
 * Created by PhpStorm.
 * BuyUser: USER
 * Date: 2018/11/12
 * Time: 10:56
 */

namespace common\sources\read\buyuser;

use common\models\craftsman\BuyUser;
use common\models\craftsman\SmsCode;

class BuyUserAccess implements IBuyUserAccess
{


    public function getBuyUser($phone)
    {
        return BuyUser::find()
            ->select('id,password,pid')
            ->where(['phone'=>$phone])
            ->asArray()
            ->one();
    }

    public function getBuyUserByPhone($phone)
    {
        return BuyUser::find()
            ->select("id,password,qq,wx,area,addr,expire_time,pid")
            ->where(['phone' => $phone,'role' => 2])
            ->asArray()
            ->one();
    }

    public function getMemberByPhone($data)
    {
        return BuyUser::find()
            ->select("id,password,qq,wx,area,addr,expire_time,pid")
            ->where(['phone' => $data['user_phone'],'role' => $data['role']])
            ->asArray()
            ->one();
    }

    public function checkMember($phone,$role)
    {
        return BuyUser::find()
            ->select("id,password,qq,wx,area,addr,expire_time,pid")
            ->where(['phone' => $phone,'role' => $role])
            ->asArray()
            ->one();
    }

    public function getBuyUserInfo($buy_Id)
    {
        return BuyUser::find()
            ->select("id,phone,password,qq,wx,area,addr,role,expire_time,pid")
            ->where(['id'=>$buy_Id])
            ->asArray()
            ->one();
    }

    public function UserBlackList($data) {
        $query = BuyUser::find()
            ->select("phone,freeze,freeze_reason,freeze_time,freeze_operator")
            ->where("freeze != 1");
        if (!empty($data['userId'])) {
            $query = $query->where(['id' => $data['userId']]);
        }
        $list = $query
            ->asArray()
            ->offset(($data['page_num']-1)*$data['limit'])
            ->limit($data['limit'])
            ->all();
        return $list;
    }

    public function CountUserBlackList($data) {
        $query = BuyUser::find()
            ->select("phone,freeze,freeze_reason,freeze_time,freeze_operator")
            ->where("freeze != 1");
        if (!empty($data['userId'])) {
            $query = $query->where(['id' => $data['userId']]);
        }
        $count = $query
            ->asArray()
            ->count();
        return $count;
    }

//    public function allBuyUserInfo($buyIds) {
//        $list = BuyUser::find()
//            ->select('phone,role,')
//    }
}